﻿using Microsoft.AspNetCore.Mvc;
using WorldmeServer.Models.Base;

namespace WorldmeServer.Controllers.文件相关
{
    [ApiController]
    [Route("api/file")]
    public class FileController : ControllerBase
    {
        [HttpGet]
        [Route("avatar/{id}")]
        [JwtNoAuthorize]
        public async Task<IActionResult> GetAvatar(string id)
        {
            if (!System.IO.File.Exists(Path.Combine(Constant.PATH_AVATAR, id)))
            {
                return NotFound();
            }
            return File(System.IO.File.ReadAllBytes(Path.Combine(Constant.PATH_AVATAR, id)), "application/octet-stream", $"{id}.png");
        }

        [HttpGet]
        [Route("texture/{id}")]
        [JwtNoAuthorize]
        public async Task<IActionResult> GetTexture(string id)
        {
            if (!System.IO.File.Exists(Path.Combine(Constant.PATH_TEXTURE, id)))
            {
                return NotFound();
            }
            return File(System.IO.File.ReadAllBytes(Path.Combine(Constant.PATH_TEXTURE, id)), "application/octet-stream", $"{id}.png");
        }
    }
}
